// pages/jblist/jblist.js
const app = getApp();
const url = app.globalData.url;
const common = require("../../utils/common.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    click:1,
    loding:true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (o) {
    console.log(o)
    if(o.ck){
      this.setData({click:o.ck})
    }
    this.peizi();
  },
    // 跳转url
  tourl(e) {
    let url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url
    })
  },
  dhbtn(e){
    this.setData({click: e.currentTarget.dataset.ck});
    this.hqjbjl();
  },
   // 配置文件
 peizi: function () {
  let that = this;
  app.fetch('api/wx/getpeizi', { dlx: 'xcxjbjl' }, "GET", (err, data) => {
    console.log(data)
    if (data.code == 200) {
        wx.setNavigationBarTitle({
          title: data.data.xcx.jb.txt+'记录'
        });
      that.setData({
        peizi:data.data
      });
      // article_content: WxParse.wxParse('article', 'html', data.data.xcxvip.tqsm.txt, that, 0);
      that.hquser();
    } else {
      wx.showModal({
        title: '接口数据错误',
        content: '接口:"' + url + 'api/wx/getpeizi.php' + '",msg:' + data.msg,
        showCancel: false,//是否显示取消按钮
        confirmText: "好的",//默认是“确定”
        confirmColor: 'skyblue',//确定文字的颜色
        success: function (res) {

        },
        fail: function (res) { },//接口调用失败的回调函数
        complete: function (res) { },//接口调用结束的回调函数（调用成功、失败都会执行）
      })
    }
  })
},
// 获取user信息;
hquser() {
  let that = this;
  wx.getStorage({
    key: 'openid',
    success(res) {
      app.fetch('api/wx/user', { openid: res.data }, "POST", (err, data) => {
        if (data.code == 200) {
          data.data[0].viptime=common.format(data.data[0].viptime);
          that.setData({ user: data.data[0],loding:false })
          // that.getcsData();
          that.hqjbjl();
        }
      })
    }
  })
},
hqjbjl(sx){
  let that = this;
  let list = [];
  let pno = 1;
  if (sx) {
    list = that.data.list;
    pno = that.data.pno;
  }
  let sj={
    uid: that.data.user.uid,
    sz: that.data.click,
    lx:'xcx',
    pno: pno
  }
  app.fetch('api/wx/getjb', sj, "POST", (err, data) => {
    var dt =data.list;
    console.log(data);
    console.log(dt);
    for (var i = 0; i < dt.length; i++) {
      let tm = dt[i].addtime;
      dt[i].addtime = common.format(tm);
      list.push(dt[i]);
    }
    let pp = Number(data.pno) + 1;
    that.setData({
      list: list,
      count: data.recordCount,
      pno: pp,
      pcount: data.pageCount,
      zjg: data.zjg,
    });
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var count = that.data.pcount;
    var pno = that.data.pno;
    console.log(pno, count)
    if (pno-1 < count) {
      that.hqjbjl('sx');
    } else {
      that.setData({ jzs:true});
      setTimeout(function () {
        that.setData({ jzs: false });
      }, 1000)
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})